package com.util;

import java.util.StringTokenizer;

public class Shell
{

    public Shell()
    {
    }

    public static void main(String args[])
        throws Exception
    {
        String args1[] = {
            "command", "host", "ftp_user", "ftp_passwd", "local_path", "file_name", "remote_path"
        };
    }

    public static int run(String as[])
    {
        Runtime runtime = Runtime.getRuntime();
        int i = -1;
        String s = "";
        try
        {
            if(!validCmd(as))
                return -1;

            Process process = runtime.exec(as);
            i = process.waitFor();
        }
        catch(Exception exception)
        {
            exception.printStackTrace();
        }
        return i;
    }

    private static boolean validCmd(String as[])
    {
        try
        {
            String s = "";
            StringTokenizer stringtokenizer = new StringTokenizer(as[0], "/");
            int i = stringtokenizer.countTokens();
            for(int j = 0; j < i; j++) {
              s = stringtokenizer.nextToken().trim();
              System.out.println(s);
            }

            int k = s.length();
            if(s.substring(k - 3).equals(".sh"))
                return true;
            return s.substring(k - 4).equals(".ksh");
        }
        catch(Exception exception)
        {
            return false;
        }
    }

    private static final boolean debug = false;
}
